import { AUTH_KEY } from "@/constant";
import { authService } from "@/services";
import axios from "axios";

const request = axios.create({
  baseURL: "http://localhost:8090",
  timeout: 30 * 1000,
});

request.interceptors.request.use((config) => {
  const token = authService.getAuth();

  if (token) {
    config.headers[AUTH_KEY] = `Bearer ${token}`;
  }

  return config;
});

request.interceptors.response.use((response) => {
  return response.data;
});

export default request;
